package com.extremelylargepackage.entity;

import com.extremelylargepackage.GameResources;
import com.extremelylargepackage.sprite.AbstractSprite;

public class Nuke extends Projectile
{
	private Player _owner;
	private AbstractSprite _flyingSprite;
	private AbstractSprite _explodingSprite;
	private boolean _exploding = false;
	private final static float FLYING_SPEED = GameResources.SCREEN_HEIGHT / 2f;
	private final static float EXPLODING_SPEED = GameResources.SCREEN_HEIGHT;
	
	public Nuke(Player owner)
	{
		super();
		_owner = owner;
		_speed = GameResources.SCREEN_HEIGHT * .5f;
		_flyingSprite = GameResources.getResource("nuke");
		_explodingSprite = GameResources.getResource("nuke_explosion");
		_sprite = _flyingSprite;
		_damage = Float.MAX_VALUE;
		_status = Status.dead;
	}
	
	@Override
	public void fire()
	{
		if(_status == Status.dead)
		{
			_sprite = _flyingSprite;
			_locX = (_owner._locX + (_owner.getWidth() / 2))- (_sprite.getWidth() / 2);
			_locY = (_owner._locY + (_owner.getHeight() / 2)) - (_sprite.getHeight() / 2);
			_status = Status.alive;
			_exploding = false;
			_speed = FLYING_SPEED;
			_dirY = -1;
		}
	}
	
	@Override
	public void updateState(long time)
	{
		super.updatePosition(time);
		if(!_exploding && _locY <= MIN_Y_BOUNDS)
		{
			_exploding = true;
			_locX = (GameResources.SCREEN_WIDTH / 2) - (_explodingSprite.getWidth() / 2);
			_dirY = 1;
			_speed = EXPLODING_SPEED;
			_sprite = _explodingSprite;
		}
		else if(_locY > MAX_Y_BOUNDS)
			_status = Status.dead;
	}
	
	public boolean isExploding()
	{
		return _exploding;
	}
	
	@Override
	public void onCollision(Entity z)
	{
		//Carry on
	}
}
